home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
clang
/
c_course.zip
/
READLINE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-12-30
|
795b
|
28 lines
/* READLINE.C fgets() do/while with test for NULL in loop */
/* fgets() gets a whole line, or rather gets characters until it sees an
EOL or until it gets the number of charcters given in second of three
parameters.
Like fscanf, the whole function takes on the value of the character stream
as it fills its (first parameter) array. That way if a NULL is read
you can detect it in a conditional. */
#include "stdio.h"
main()
{
FILE *fp1;
char oneword[100];
char *c;
fp1 = fopen("TENLINES.TXT","r");
do {
c = fgets(oneword,100,fp1); /* get one line from the file */
if (c != NULL)
printf("%s",oneword); /* display it on the monitor */
} while (c != NULL); /* repeat until NULL */
fclose(fp1);
}